package com.gao.x_synchronousqueue;

import java.util.concurrent.SynchronousQueue;

/**
 * @author gao
 * @time 2021/04/20 22:31:46
 */
public class App {
    public static void main(String[] args) throws Exception {
        SynchronousQueue<Integer> queue = new SynchronousQueue<>(false);

        Thread th = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("put thread start");
                try {
                    Integer i = 1;
                    queue.put(i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("put thread end");
            }
        });

        Thread th2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("take thread start");
                try {
                    Integer i = queue.take();
                    System.out.println("take: " + i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("take thread end");
            }
        });

        th.start();
        Thread.sleep(3000);
        th2.start();
    }
}
